package com.lanfan.controller.web;

import com.lanfan.entity.ResponseResult;
import com.lanfan.entity.Todaymenu;
import com.lanfan.service.TodaymenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController("webTodaymenuController")
@RequestMapping("/web/todaymenu")
public class TodaymenuController {
    @Resource
    private TodaymenuService todaymenuService;
    @GetMapping("/getTodaymenuList")
    public ResponseResult getTodaymenuList(){
        ResponseResult responseResult=new ResponseResult<>();
        List<Todaymenu> todaymenuList=todaymenuService.getTodaymenuList();
        responseResult.setDate(todaymenuList);
        return responseResult;
    }

    @PostMapping("/increasePopularity")
    public ResponseResult<Void> increasePopularity(@RequestBody Map<String, Integer> params) {
        Integer tid = params.get("tid");
        if (tid == null) {
            return new ResponseResult<>(400, "参数错误", null);
        }
        boolean success = todaymenuService.increasePopularity(tid);
        if (success) {
            return new ResponseResult<>(200, null, null);
        } else {
            return new ResponseResult<>(500, "增加热度失败", null);
        }
    }
    @GetMapping("/search-exact")
    public ResponseResult<List<Todaymenu>> searchMenusExact(@RequestParam String keyword) {
        ResponseResult responseResult=new ResponseResult<>();
        List<Todaymenu> results = todaymenuService.searchMenusExact(keyword);
        responseResult.setDate(results);
        return responseResult;
    }
}
